home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
awe2-0_1.lha
/
awe2-0.1
/
Src
/
RCS
/
GenericTree.h,v
< prev
next >
Wrap
Text File
|
1988-10-12
|
3KB
|
157 lines
head 1.1;
access ;
symbols ;
locks grunwald:1.1; strict;
comment @ * @;
1.1
date 88.09.18.16.42.07; author grunwald; state Exp;
branches ;
next ;
desc
@@
1.1
log
@Initial revision
@
text
@//
// Define the following things:
// TREE_NAME -- the name of the tree type
// TREE_INDEX -- the index type; defaults to unsigned short
// TREE_KEY -- the key type; defaults to double
// TREE_ITEM -- the type name for an item; should be typedefed
// TREE_INDEX_NULL -- the null value for the tree index; defaults to 65535
// TREE_BASE_CLASS -- the base class for the new tree
//
#include "Awesime.h"
#include "Generic.h"
#ifndef TREE_INDEX
#define TREE_INDEX unsigned short
#endif
#ifndef TREE_INDEX_NULL
#define TREE_INDEX_NULL 0xffff
#endif
#ifndef TREE_KEY
#define TREE_KEY double
#endif
#ifndef TREE_BASE_CLASS
#define TREE_BASE_CLASS public Awesime
#endif
typedef TREE_ITEM GENERIC2(TREE_NAME,Item);
typedef TREE_KEY GENERIC2(TREE_NAME,Key);
typedef TREE_INDEX GENERIC2(TREE_NAME,Index);
extern const GENERIC2(TREE_NAME,Index) GENERIC2(TREE_NAME,Null);
typedef struct {
GENERIC2(TREE_NAME,Key) key;
GENERIC2(TREE_NAME,Item) item;
GENERIC2(TREE_NAME,Index) left;
GENERIC2(TREE_NAME,Index) right;
} GENERIC2(TREE_NAME,Record);
class TREE_NAME : TREE_BASE_CLASS {
GENERIC2(TREE_NAME,Record) *storage;
char *pValid;
int elements;
GENERIC2(TREE_NAME,Index) allocatedSize;
GENERIC2(TREE_NAME,Index) freelist;
GENERIC2(TREE_NAME,Index) root;
inline GENERIC2(TREE_NAME,Index) &left(GENERIC2(TREE_NAME,Index) p) {
return(&(storage[p].left));
}
inline GENERIC2(TREE_NAME,Index) &right(GENERIC2(TREE_NAME,Index) p) {
return(&(storage[p].right));
}
inline GENERIC2(TREE_NAME,Key) &key(GENERIC2(TREE_NAME,Index) p) {
return(&(storage[p].key));
}
inline GENERIC2(TREE_NAME,Item) &item(GENERIC2(TREE_NAME,Index) p) {
return(&(storage[p].item));
}
void makeRoom(int atLeast);
inline GENERIC2(TREE_NAME,Index) getCell() {
if (freelist == GENERIC2(TREE_NAME,Null)) {
makeRoom();
}
GENERIC2(TREE_NAME,Index) cell = freelist;
pValid[freelist] = 1;
freelist = storage[freelist].sibling;
elements++;
return(cell);
}
inline void returnCell(GENERIC2(TREE_NAME,Index) cell) {
storage[cell].sibling = freelist;
pValid[cell] = 0;
freelist = cell;
elements--;
}
public:
TREE_NAME(int length = 0, bool xdebug = 0);
void add(GENERIC2(TREE_NAME,Key) *key, GENERIC2(TREE_NAME,Item) *item);
bool remove(GENERIC2(TREE_NAME,Key) *key,
GENERIC2(TREE_NAME,Item) *removed);
inline GENERIC2(TREE_NAME,Index) minItem() {
return(root);
};
inline bool valid(GENERIC2(TREE_NAME,Index) index) {
return ( pValid[index] );
}
inline GENERIC2(TREE_NAME,Key) & key(GENERIC2(TREE_NAME,Index) i) {
return( storage[i].key );
}
inline GENERIC2(TREE_NAME,Item) & item(GENERIC2(TREE_NAME,Index) i) {
return( storage[i].item );
}
inline GENERIC2(TREE_NAME,Index) maxIndex() {
return(allocatedSize);
}
inline bool isEmpty() {
return(elements <= 0);
}
inline unsigned int size() {
return(elements);
}
virtual void classPrintOn(ostream& s);
};
#undef TREE_NAME
#undef TREE_ITEM
#undef TREE_KEY
#undef TREE_INDEX
#undef TREE_BASE_CLASS
@